package debugServer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import YAPenvironment.YAPconstant;
import YAPserver.FormServer;

@SuppressWarnings("serial")
public class FormDebugServer extends FormServer{
	
	JMenuItem openConsole = new JMenuItem("Open Debug Console");
	JMenuItem showError = new JCheckBoxMenuItem("Show Debug Trace");
	
	FormDebugServer() {
		super();
		addDebugMenu();
	}
	
	private void addDebugMenu(){
		JMenu debugMenu = new JMenu("Debug");
		DebugListener listener = new DebugListener();
		
		showError.addActionListener(listener);
		openConsole.addActionListener(listener);
		
		debugMenu.add(showError);
		debugMenu.add(openConsole);
		
		this.jMenuBar.add(debugMenu);
	}
	
	private class DebugListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource().equals(openConsole)){
				new FormDebugConsole();
				showError.setSelected(true);
				YAPconstant.setDebug(true);
			}
			if(e.getSource().equals(showError)){
				if(showError.isSelected()){
					YAPconstant.setDebug(true);
				}else{
					YAPconstant.setDebug(false);
				}
			}
		}
		
	}
}
